home *** CD-ROM | disk | FTP | other *** search
/ Eidos Line Up 2003-04 (Germany) / Eidos Line Up 2003-04 (Germany).bin / commandos3.swf / scripts / FScrollBarSymbol.as next >
Text File  |  2003-08-06  |  12KB  |  363 lines

  1. FScrollBarClass = function()
  2. {
  3.    if(this._height == 4)
  4.    {
  5.       return undefined;
  6.    }
  7.    this.init();
  8.    this.minPos = this.maxPos = this.pageSize = this.largeScroll = 0;
  9.    this.smallScroll = 1;
  10.    this.width = !this.horizontal ? this._height : this._width;
  11.    this._xscale = this._yscale = 100;
  12.    this.setScrollPosition(0);
  13.    this.tabEnabled = false;
  14.    if(this._targetInstanceName.length > 0)
  15.    {
  16.       this.setScrollTarget(this._parent[this._targetInstanceName]);
  17.    }
  18.    this.tabChildren = false;
  19.    this.setSize(this.width);
  20. };
  21. FScrollBarClass.prototype = new FUIComponentClass();
  22. FScrollBarClass.prototype.setHorizontal = function(flag)
  23. {
  24.    if(this.horizontal && !flag)
  25.    {
  26.       this._xscale = 100;
  27.       this._rotation = 0;
  28.    }
  29.    else if(flag && !this.horizontal)
  30.    {
  31.       this._xscale = -100;
  32.       this._rotation = -90;
  33.    }
  34.    this.horizontal = flag;
  35. };
  36. FScrollBarClass.prototype.setScrollProperties = function(pSize, mnPos, mxPos)
  37. {
  38.    if(!this.enable)
  39.    {
  40.       return undefined;
  41.    }
  42.    this.pageSize = pSize;
  43.    this.minPos = Math.max(mnPos,0);
  44.    this.maxPos = Math.max(mxPos,0);
  45.    this.scrollPosition = Math.max(this.minPos,this.scrollPosition);
  46.    this.scrollPosition = Math.min(this.maxPos,this.scrollPosition);
  47.    if(this.maxPos - this.minPos <= 0)
  48.    {
  49.       this.scrollThumb_mc.removeMovieClip();
  50.       this.upArrow_mc.gotoAndStop(3);
  51.       this.downArrow_mc.gotoAndStop(3);
  52.       this.downArrow_mc.onPress = this.downArrow_mc.onRelease = this.downArrow_mc.onDragOut = null;
  53.       this.upArrow_mc.onPress = this.upArrow_mc.onRelease = this.upArrow_mc.onDragOut = null;
  54.       this.scrollTrack_mc.onPress = this.scrollTrack_mc.onRelease = null;
  55.       this.scrollTrack_mc.onDragOut = this.scrollTrack_mc.onRollOut = null;
  56.       this.scrollTrack_mc.useHandCursor = false;
  57.    }
  58.    else
  59.    {
  60.       var tmp = this.getScrollPosition();
  61.       this.upArrow_mc.gotoAndStop(1);
  62.       this.downArrow_mc.gotoAndStop(1);
  63.       this.upArrow_mc.onPress = this.upArrow_mc.onDragOver = this.startUpScroller;
  64.       this.upArrow_mc.onRelease = this.upArrow_mc.onDragOut = this.stopScrolling;
  65.       this.downArrow_mc.onPress = this.downArrow_mc.onDragOver = this.startDownScroller;
  66.       this.downArrow_mc.onRelease = this.downArrow_mc.onDragOut = this.stopScrolling;
  67.       this.scrollTrack_mc.onPress = this.scrollTrack_mc.onDragOver = this.startTrackScroller;
  68.       this.scrollTrack_mc.onRelease = this.stopScrolling;
  69.       this.scrollTrack_mc.onDragOut = this.stopScrolling;
  70.       this.scrollTrack_mc.onRollOut = this.stopScrolling;
  71.       this.scrollTrack_mc.useHandCursor = false;
  72.       this.attachMovie("ScrollThumb","scrollThumb_mc",3);
  73.       this.scrollThumb_mc._x = 0;
  74.       this.scrollThumb_mc._y = this.upArrow_mc._height;
  75.       this.scrollThumb_mc.onPress = this.startDragThumb;
  76.       this.scrollThumb_mc.controller = this;
  77.       this.scrollThumb_mc.onRelease = this.scrollThumb_mc.onReleaseOutside = this.stopDragThumb;
  78.       this.scrollThumb_mc.useHandCursor = false;
  79.       this.thumbHeight = this.pageSize / (this.maxPos - this.minPos + this.pageSize) * this.trackSize;
  80.       this.thumbMid_mc = this.scrollThumb_mc.mc_sliderMid;
  81.       this.thumbTop_mc = this.scrollThumb_mc.mc_sliderTop;
  82.       this.thumbBot_mc = this.scrollThumb_mc.mc_sliderBot;
  83.       this.thumbHeight = Math.max(this.thumbHeight,6);
  84.       this.midHeight = this.thumbHeight - this.thumbTop_mc._height - this.thumbBot_mc._height;
  85.       this.thumbMid_mc._yScale = this.midHeight * 100 / this.thumbMid_mc._height;
  86.       this.thumbMid_mc._y = this.thumbTop_mc._height;
  87.       this.thumbBot_mc._y = this.thumbTop_mc._height + this.midHeight;
  88.       this.scrollTop = this.scrollThumb_mc._y;
  89.       this.trackHeight = this.trackSize - this.thumbHeight;
  90.       this.scrollBot = this.trackHeight + this.scrollTop;
  91.       tmp = Math.min(tmp,this.maxPos);
  92.       this.setScrollPosition(Math.max(tmp,this.minPos));
  93.    }
  94. };
  95. FScrollBarClass.prototype.getScrollPosition = function()
  96. {
  97.    return this.scrollPosition;
  98. };
  99. FScrollBarClass.prototype.setScrollPosition = function(pos)
  100. {
  101.    this.scrollPosition = pos;
  102.    if(this.scrollThumb_mc != undefined)
  103.    {
  104.       pos = Math.min(pos,this.maxPos);
  105.       pos = Math.max(pos,this.minPos);
  106.    }
  107.    this.scrollThumb_mc._y = (pos - this.minPos) * this.trackHeight / (this.maxPos - this.minPos) + this.scrollTop;
  108.    this.executeCallBack();
  109. };
  110. FScrollBarClass.prototype.setLargeScroll = function(lScroll)
  111. {
  112.    this.largeScroll = lScroll;
  113. };
  114. FScrollBarClass.prototype.setSmallScroll = function(sScroll)
  115. {
  116.    this.smallScroll = sScroll;
  117. };
  118. FScrollBarClass.prototype.setEnabled = function(enabledFlag)
  119. {
  120.    var wasEnabled = this.enable;
  121.    if(enabledFlag && !wasEnabled)
  122.    {
  123.       this.enable = enabledFlag;
  124.       if(this.textField != undefined)
  125.       {
  126.          this.setScrollTarget(this.textField);
  127.       }
  128.       else
  129.       {
  130.          this.setScrollProperties(this.pageSize,this.cachedMinPos,this.cachedMaxPos);
  131.          this.setScrollPosition(this.cachedPos);
  132.       }
  133.       this.clickFilter = undefined;
  134.    }
  135.    else if(!enabledFlag && wasEnabled)
  136.    {
  137.       this.textField.removeListener(this);
  138.       this.cachedPos = this.getScrollPosition();
  139.       this.cachedMinPos = this.minPos;
  140.       this.cachedMaxPos = this.maxPos;
  141.       if(this.clickFilter == undefined)
  142.       {
  143.          this.setScrollProperties(this.pageSize,0,0);
  144.       }
  145.       else
  146.       {
  147.          this.clickFilter = true;
  148.       }
  149.       this.enable = enabledFlag;
  150.    }
  151. };
  152. FScrollBarClass.prototype.setSize = function(hgt)
  153. {
  154.    if(this._height == 1)
  155.    {
  156.       return undefined;
  157.    }
  158.    this.width = hgt;
  159.    this.scrollTrack_mc._yscale = 100;
  160.    this.scrollTrack_mc._yscale = 100 * this.width / this.scrollTrack_mc._height;
  161.    if(this.upArrow_mc == undefined)
  162.    {
  163.       this.attachMovie("UpArrow","upArrow_mc",1);
  164.       this.attachMovie("DownArrow","downArrow_mc",2);
  165.       this.downArrow_mc.controller = this.upArrow_mc.controller = this;
  166.       this.upArrow_mc.useHandCursor = this.downArrow_mc.useHandCursor = false;
  167.       this.upArrow_mc._x = this.upArrow_mc._y = 0;
  168.       this.downArrow_mc._x = 0;
  169.    }
  170.    this.scrollTrack_mc.controller = this;
  171.    this.downArrow_mc._y = this.width - this.downArrow_mc._height;
  172.    this.trackSize = this.width - 2 * this.downArrow_mc._height;
  173.    if(this.textField != undefined)
  174.    {
  175.       this.onTextChanged();
  176.    }
  177.    else
  178.    {
  179.       this.setScrollProperties(this.pageSize,this.minPos,this.maxPos);
  180.    }
  181. };
  182. FScrollBarClass.prototype.scrollIt = function(inc, mode)
  183. {
  184.    var delt = this.smallScroll;
  185.    if(inc != "one")
  186.    {
  187.       delt = this.largeScroll != 0 ? this.largeScroll : this.pageSize;
  188.    }
  189.    var newPos = this.getScrollPosition() + mode * delt;
  190.    if(newPos > this.maxPos)
  191.    {
  192.       newPos = this.maxPos;
  193.    }
  194.    else if(newPos < this.minPos)
  195.    {
  196.       newPos = this.minPos;
  197.    }
  198.    this.setScrollPosition(newPos);
  199. };
  200. FScrollBarClass.prototype.startDragThumb = function()
  201. {
  202.    this.lastY = this._ymouse;
  203.    this.onMouseMove = this.controller.dragThumb;
  204. };
  205. FScrollBarClass.prototype.dragThumb = function()
  206. {
  207.    this.scrollMove = this._ymouse - this.lastY;
  208.    this.scrollMove += this._y;
  209.    if(this.scrollMove < this.controller.scrollTop)
  210.    {
  211.       this.scrollMove = this.controller.scrollTop;
  212.    }
  213.    else if(this.scrollMove > this.controller.scrollBot)
  214.    {
  215.       this.scrollMove = this.controller.scrollBot;
  216.    }
  217.    this._y = this.scrollMove;
  218.    var c = this.controller;
  219.    c.scrollPosition = Math.round((c.maxPos - c.minPos) * (this._y - c.scrollTop) / c.trackHeight) + c.minPos;
  220.    this.controller.isScrolling = true;
  221.    updateAfterEvent();
  222.    this.controller.executeCallBack();
  223. };
  224. FScrollBarClass.prototype.stopDragThumb = function()
  225. {
  226.    this.controller.isScrolling = false;
  227.    this.onMouseMove = null;
  228. };
  229. FScrollBarClass.prototype.startTrackScroller = function()
  230. {
  231.    this.controller.trackScroller();
  232.    this.controller.scrolling = setInterval(this.controller,"scrollInterval",500,"page",-1);
  233. };
  234. FScrollBarClass.prototype.scrollInterval = function(inc, mode)
  235. {
  236.    clearInterval(this.scrolling);
  237.    if(inc == "page")
  238.    {
  239.       this.trackScroller();
  240.    }
  241.    else
  242.    {
  243.       this.scrollIt(inc,mode);
  244.    }
  245.    this.scrolling = setInterval(this,"scrollInterval",35,inc,mode);
  246. };
  247. FScrollBarClass.prototype.trackScroller = function()
  248. {
  249.    if(this.scrollThumb_mc._y + this.thumbHeight < this._ymouse)
  250.    {
  251.       this.scrollIt("page",1);
  252.    }
  253.    else if(this.scrollThumb_mc._y > this._ymouse)
  254.    {
  255.       this.scrollIt("page",-1);
  256.    }
  257. };
  258. FScrollBarClass.prototype.stopScrolling = function()
  259. {
  260.    this.controller.downArrow_mc.gotoAndStop(1);
  261.    this.controller.upArrow_mc.gotoAndStop(1);
  262.    clearInterval(this.controller.scrolling);
  263. };
  264. FScrollBarClass.prototype.startUpScroller = function()
  265. {
  266.    this.controller.upArrow_mc.gotoAndStop(2);
  267.    this.controller.scrollIt("one",-1);
  268.    this.controller.scrolling = setInterval(this.controller,"scrollInterval",500,"one",-1);
  269. };
  270. FScrollBarClass.prototype.startDownScroller = function()
  271. {
  272.    this.controller.downArrow_mc.gotoAndStop(2);
  273.    this.controller.scrollIt("one",1);
  274.    this.controller.scrolling = setInterval(this.controller,"scrollInterval",500,"one",1);
  275. };
  276. FScrollBarClass.prototype.setScrollTarget = function(tF)
  277. {
  278.    if(tF == undefined)
  279.    {
  280.       this.textField.removeListener(this);
  281.       delete this.textField[!this.horizontal ? "vScroller" : "hScroller"];
  282.       if(this.textField.hScroller != undefined && this.textField.vScroller != undefined)
  283.       {
  284.          this.textField.unwatch("text");
  285.          this.textField.unwatch("htmltext");
  286.       }
  287.    }
  288.    this.textField = undefined;
  289.    if(!(tF instanceof TextField))
  290.    {
  291.       return undefined;
  292.    }
  293.    this.textField = tF;
  294.    this.textField[!this.horizontal ? "vScroller" : "hScroller"] = this;
  295.    this.onTextChanged();
  296.    this.onChanged = function()
  297.    {
  298.       this.onTextChanged();
  299.    };
  300.    this.onScroller = function()
  301.    {
  302.       if(!this.isScrolling)
  303.       {
  304.          if(!this.horizontal)
  305.          {
  306.             this.setScrollPosition(this.textField.scroll);
  307.          }
  308.          else
  309.          {
  310.             this.setScrollPosition(this.textField.hscroll);
  311.          }
  312.       }
  313.    };
  314.    this.textField.addListener(this);
  315.    this.textField.watch("text",this.callback);
  316.    this.textField.watch("htmlText",this.callback);
  317. };
  318. FScrollBarClass.prototype.callback = function(prop, oldVal, newVal)
  319. {
  320.    clearInterval(this.hScroller.synchScroll);
  321.    clearInterval(this.vScroller.synchScroll);
  322.    this.hScroller.synchScroll = setInterval(this.hScroller,"onTextChanged",50);
  323.    this.vScroller.synchScroll = setInterval(this.vScroller,"onTextChanged",50);
  324.    return newVal;
  325. };
  326. FScrollBarClass.prototype.onTextChanged = function()
  327. {
  328.    if(!this.enable || this.textField == undefined)
  329.    {
  330.       return undefined;
  331.    }
  332.    clearInterval(this.synchScroll);
  333.    if(this.horizontal)
  334.    {
  335.       var pos = this.textField.hscroll;
  336.       this.setScrollProperties(this.textField._width,0,this.textField.maxhscroll);
  337.       this.setScrollPosition(Math.min(pos,this.textField.maxhscroll));
  338.    }
  339.    else
  340.    {
  341.       var pos = this.textField.scroll;
  342.       var pageSize = this.textField.bottomScroll - this.textField.scroll;
  343.       this.setScrollProperties(pageSize,1,this.textField.maxscroll);
  344.       this.setScrollPosition(Math.min(pos,this.textField.maxscroll));
  345.    }
  346. };
  347. FScrollBarClass.prototype.executeCallBack = function()
  348. {
  349.    if(this.textField == undefined)
  350.    {
  351.       super.executeCallBack();
  352.    }
  353.    else if(this.horizontal)
  354.    {
  355.       this.textField.hscroll = this.getScrollPosition();
  356.    }
  357.    else
  358.    {
  359.       this.textField.scroll = this.getScrollPosition();
  360.    }
  361. };
  362. Object.registerClass("FScrollBarSymbol",FScrollBarClass);
  363.